package com.bdqn.design;

import com.bdqn.design.counter.*;

import java.util.Scanner;

/**
 * Test03CounterFactory
 *
 * @author LILIBO
 * @since 2024/7/4
 */
public class Test03CounterFactory {

    private static final Scanner input = new Scanner(System.in);

    public static CounterFactory getFactory(String option) {
        switch (option) {
            case "+":
                return new CounterAdditionFactory();
            case "-":
                return new CounterSubductionFactory();
            case "*":
                return new CounterMultiplyFactory();
            case "/":
                return new CounterDivisionFactory();
            case "%":
                return new CounterModFactory();
            default:
                throw new RuntimeException("还未有此计算器问世！");
        }
    }

    public static void main(String[] args) {
        System.out.print("请输入第一个数：");
        double num1 = input.nextDouble();
        System.out.print("请输入第二个数：");
        double num2 = input.nextDouble();
        System.out.print("请输入计算方式：");
        String option = input.next();
        CounterFactory factory = getFactory(option);
        CounterProduct instance = factory.getInstance();
        // 相加运算
        double result = instance.compute(num1, num2);
        System.out.println("计算结果：\n" + num1 + " " + option + " " + num2 + " = " + result);
    }

}
